package com.zhu.androidsample.business.girls.adpter;

import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.zhu.androidsample.R;
import com.zhu.androidsample.business.girls.bean.GirlBean;
import com.zhu.androidsample.common.BaseAdapter;
import com.zhu.androidsample.util.ToastUtil;

/**
 * 一个RecyclerView的Adapter中包括:
 * 1.一个ViewHolder（继承自RecyclerView中的内部类ViewHolder）
 * 2.一个数据容器
 * 3.重写的各种方法
 * Created by ZCP on 2015/11/20.
 * mail:43426073@qq.com
 */
public class GirlAdapter extends BaseAdapter {

    @Override
    public GirlViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GirlViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.view_list_gril, parent, false));
    }

    @Override
    public void onItemClick(View view, int position, long id) {
        ToastUtil.show("View:" + view + "  position:" + position);
    }

    public class GirlViewHolder extends BaseViewHolder {
        SimpleDraweeView girl;
        TextView title;

        public GirlViewHolder(View itemView) {
            super(itemView);
            girl = (SimpleDraweeView) itemView.findViewById(R.id.view_girl_image);
            title = (TextView) itemView.findViewById(R.id.view_girl_title);
        }

        @Override
        public void setBean(Object o) {
            GirlBean bean = (GirlBean) o;
            bean.getUrl();
            Uri uri = Uri.parse(bean.getPicUrl());
            girl.setAspectRatio(0.75f);
            girl.setImageURI(uri);
            title.setText(bean.getTitle());
        }


    }
}
